package com.hospital.controller;

import com.hospital.domain.pojo.Drug;
import com.hospital.domain.pojo.DrugCategory;
import com.hospital.domain.utils.Result;
import com.hospital.service.DrugCategoryService;
import com.hospital.service.DrugService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/drug")
public class DrugController {

    private final DrugCategoryService categoryService;
    private final DrugService drugService;

    @GetMapping("/category/list")
    public Result<List<DrugCategory>> listCategories(){
        return Result.ok(categoryService.list());
    }

    @GetMapping("/list")
    public Result<List<Drug>> listDrugs(@RequestParam(value = "cId", required = false) Integer cId){
        if (cId == null) return Result.ok(drugService.list());
        return Result.ok(drugService.lambdaQuery().eq(Drug::getCId, cId).list());
    }
}

